package com.itheima.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.MemberDao;
import com.itheima.dao.OrderDao;
import com.itheima.dao.SetMealDao;
import com.itheima.utils.DateUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service
@Slf4j
public class ReportServiceImpl implements ReportService {

    @Autowired
    private MemberDao memberDao;
    @Autowired
    private OrderDao orderDao;
    @Autowired
    private SetMealDao setMealDao;

    @Override
    public Map<String, Object> getBusinessReport() throws Exception {
        String today = DateUtils.parseDate2String(new Date());
        String thisWeekFirstDay = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
        String thisWeekLastDay = DateUtils.parseDate2String(DateUtils.getSundayOfThisWeek());
        String thisMonthFirstDay = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());
        String thisMonthLastDay = DateUtils.parseDate2String(DateUtils.getLastDay4ThisMonth());

        String reportDate = today;
        long todayNewMember = memberDao.findTodayNewMember(today);
        long totalMember = memberDao.findTotalCount();
        long thisWeekNewMember = memberDao.findMember(thisWeekFirstDay);
        long thisMonthNewMember = memberDao.findMember(thisMonthFirstDay);
        long todayOrderNumber = orderDao.findTodayOrderNumber(today);
        long todayVisitsNumber = orderDao.findTodayVisitsNumber(today);
        long thisWeekOrderNumber = orderDao.findOrderNumber(thisWeekFirstDay,thisWeekLastDay);
        long thisWeekVisitsNumber = orderDao.findVisitsNumber(thisWeekFirstDay);
        long thisMonthOrderNumber = orderDao.findOrderNumber(thisMonthFirstDay,thisMonthLastDay);
        long thisMonthVisitsNumber = orderDao.findVisitsNumber(thisMonthFirstDay);
        List<Map<String,Object>> hotSetmeal = setMealDao.getHotSetMeal();

        Map<String,Object> map = new HashMap<String, Object>();
        map.put("reportDate",reportDate);
        map.put("todayNewMember",todayNewMember);
        map.put("totalMember",totalMember);
        map.put("thisWeekNewMember",thisWeekNewMember);
        map.put("thisMonthNewMember",thisMonthNewMember);
        map.put("todayOrderNumber",todayOrderNumber);
        map.put("todayVisitsNumber",todayVisitsNumber);
        map.put("thisWeekOrderNumber",thisWeekOrderNumber);
        map.put("thisWeekVisitsNumber",thisWeekVisitsNumber);
        map.put("thisMonthOrderNumber",thisMonthOrderNumber);
        map.put("thisMonthVisitsNumber",thisMonthVisitsNumber);
        map.put("hotSetmeal",hotSetmeal);

        log.debug("ReportServiceImpl: getBusinessReport: map ===> " + map);

        return map;
    }
}
